﻿using System;
using System.Web.Services;
using Monkey.Warrenty.Biz;
using Monkey.Warrenty.EntityModel;

namespace MonkeyWarranty.Web.Customers
{
    public partial class List : System.Web.UI.Page
    {
        #region Properties

        private static CustomerBiz _customerBiz;
        private static CustomerBiz CustomerManager
        {
            get { return _customerBiz ?? (_customerBiz = new CustomerBiz()); }
        }

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                var groups = CustomerManager.GetAllCustomerGroups();//_repository.CityRepository.GetAllCustomerGroups();
                groups.Insert(0, new CustomerGroup { Id = 0, Name = Resources.GlobalStrings.AllGroups });

                ddlCustomerGroups.DataTextField = "Name";
                ddlCustomerGroups.DataValueField = "Id";
                ddlCustomerGroups.DataSource = groups;
                ddlCustomerGroups.DataBind();
            }
        }

        #region Customer methods

        [WebMethod(EnableSession = true)]
        public static object CustomerListByFilter(string name, int customerGroupId, int jtStartIndex, int jtPageSize, string jtSorting)
        {
            return CustomerManager.CustomerListByFilter(name, customerGroupId, jtStartIndex, jtPageSize, jtSorting);
        }

        [WebMethod(EnableSession = true)]
        public static object CreateCustomer(Customer record)
        {
            return CustomerManager.CreateCustomer(record);
        }

        [WebMethod(EnableSession = true)]
        public static object UpdateCustomer(Customer record)
        {
            return CustomerManager.UpdateCustomer(record);
        }

        [WebMethod(EnableSession = true)]
        public static object DeleteCustomer(int Id)
        {
            return CustomerManager.DeleteCustomer(Id);
        }

        #endregion

        #region CusmtomerGroup methods

        [WebMethod(EnableSession = true)]
        public static object GetCustomerGroupOptions()
        {
            return CustomerManager.GetCustomerGroupOptions();
        }

        #endregion
    }
}